const doc = document.querySelector('body')
doc.onmousedown = function(e) {
    if (e.target.className === 'el-dialog__header') {
        // const el = document.querySelector('.el-dialog')
        const el = e.target.parentElement
        console.log(el)
        const dialogHeaderEl = el.querySelector('.el-dialog__header');
        const sty = (function () {
            if (window.document.currentStyle) {
                return (dom, attr) => dom.currentStyle[attr];
            } else {
                return (dom, attr) => getComputedStyle(dom, false)[attr];
            }
        })()
            // 鼠标按下，计算当前元素距离可视区的距离
            let styL = sty(el, 'left').replace('px', '');
            let styT = sty(el, 'top').replace('px', '');
            let width = sty(el,'width').replace('px', '')
            let height = sty(el,'height').replace('px', '')
            const disX = e.clientX - styL;
            const disY = e.clientY - styT;

            const screenWidth = document.body.clientWidth; // body当前宽度
            const screenHeight = document.documentElement.clientHeight; // 可见区域高度(应为body高度，可某些环境下无法获取) 

            // 获取到的值带px 正则匹配替换
            document.onmousemove = function (e) {
                // 通过事件委托，计算移动的距离 
                let left = e.clientX - disX;
                let top = e.clientY - disY;

                // 边界处理
                if (left < width/2) {
                    left = width/2;
                } else if (left > screenWidth - width/2) {
                    left = screenWidth - width/2;
                }

                // if (-(top) > minDragDomTop) {
                //     top = -(minDragDomTop);
                // } else if (top > maxDragDomTop) {
                //     top = maxDragDomTop;
                // }

                // 移动当前元素  
                
                el.style.cssText = `left:${left}px;top:${top}px;width: ${width}px`;
            };

            document.onmouseup = function (e) {
                document.onmousemove = null;
                document.onmouseup = null;
            };
        }

    }